

package q10.Visitor;

/**
 *
 * @author valicu
 */

import q10.Arbori.ArboreFunctional;
import q10.Arbori.Nod;
import q10.Functii.Functie;
import q10.Functii.FunctiiElementare.Constanta;
import q10.Functii.FunctiiElementare.Necunoscuta;
import q10.Functii.FunctiiTrigonometrice.Cos;
import q10.Functii.FunctiiTrigonometrice.Sin;
import q10.Operatori.Cat;
import q10.Operatori.Minus;
import q10.Operatori.Operator;
import q10.Operatori.Plus;
import q10.Operatori.Produs;

public class ToStringVisitor extends Visitor {
	private String s;

	public ToStringVisitor() {
		s = "";
	}

	public ToStringVisitor(String s) {
		this.s = s;
	}

	public String getS() {
		return s;
	}

	public void setS(String s) {
		this.s = s;
	}

	public void visitare(Operator p) {
		if (p.getfStang() != null && p.getfDrept() != null) {
			visit(p.getfStang());
			String s1 = this.s;
			visit(p.getfDrept());
			String s2 = this.s;
			s = p.concatTermeni(s1, s2);
		}
	}

	@Override
	public void visit(Plus p) {
		visitare(p);
	}

	@Override
	public void visit(Minus p) {
		visitare(p);
	}

	@Override
	public void visit(Cat p) {
		visitare(p);
	}

	@Override
	public void visit(Produs p) {
		visitare(p);
	}


	@Override
	public void visit(Necunoscuta n) {
		this.s = "x";
	}

	@Override
	public void visit(Constanta co) {
		this.s = Double.toString(co.getCt());
	}

	public void visitare(Functie p) {
		if (p.getfStang() != null) {
			visit(p.getfStang());
			String s1 = this.s;
			s = p.concatTermeni(s1);
		}
	}

	@Override
	public void visit(Sin p) {
		visitare(p);
	}

	@Override
	public void visit(Cos p) {
		visitare(p);
	}

	@Override
	public void visit(Nod n) {
		visit(n);
	}

	public void visit(ArboreFunctional a) {
                visit(a);
	}

}
